package cn.com.dashihui.web.common;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

/**
 * 系统常量获取<br/>
 * 从数据库t_sys_config表获取
 */
public class SysConfig {
	private static final String LEVEL2_LINE_CODE = "S0001";
	private static final String signSpoint = "S0002";//每日签到赠送积分
	private static final String spoint = "";//每日签到赠送积分
	private static final String jpoint = "";//惠券比例
	private static final String kpoint = "";//抵扣券比例
	private static final String rechargeAward = "P0001";//充值奖励比例
	private static final String GROUPDOWNGIVED = "S0018";//团购结束，给予没免单用户  代金券比例
	private static final String GROUPDOWNGIVEJ = "S0019";//团购结束，给予没免单用户  积分比例
	/**
	  * 获取团购结束，给予没免单用户  积分比例
	  * @return
	  * @throws Exception
	  */
	 public static double getGroupDownGiveJ() throws Exception {
	  return (double)getFinalValue(GROUPDOWNGIVEJ);
	 }
	 /**
	  * 获取团购结束，给予没免单用户  代金券比例
	  * @return
	  * @throws Exception
	  */
	 public static double getGroupDownGiveD() throws Exception {
	  return (double)getFinalValue(GROUPDOWNGIVED);
	 }
	/**
	 * 获取充值奖励
	 * @return
	 * @throws Exception
	 */
	public static double getRechargeAward() throws Exception {
		return (double)getFinalValue(rechargeAward);
	}
	
	public static double getsignCode() throws Exception {
		return (double)getFinalValue(signSpoint);
	}

	
	public static double getLevel2LineCode() throws Exception {
		return (double)getFinalValue(LEVEL2_LINE_CODE);
	}


	public static double getSpoint() throws Exception {
		return (double)getFinalValue(spoint);
	}


	public static double getJpoint() throws Exception {
		return (double)getFinalValue(jpoint);
	}


	public static double getKpoint() throws Exception {
		return (double)getFinalValue(kpoint);
	}


	/**
	 * 根据常量字符串获取对应的常量值
	 *@param code 系统常量表中存在的code
	 * @throws Exception 
	 */
	public static Object getFinalValue(String code) throws Exception{
		Record config = Db.findFirst("SELECT value FROM t_sys_config WHERE code=?",code);
		if(config!=null){
			return Double.valueOf(config.getStr("value"));
		}
		throw new Exception("系统配置常量（代码："+code+"）对应的值找不到!");
	}
}
